package com.duobaoyu.dby.supply.biz.client.resource.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.common.core.constant.SecurityConstants;
import com.duobaoyu.dby.common.core.constant.ServiceNameConstants;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.resource.admin.feign.RemoteResourceDictionaryAdminService;
import com.duobaoyu.dby.resource.common.admin.to.config.DictionaryTO;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceDictionaryAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.DictionaryDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.DictionaryVO;
import com.duobaoyu.dby.supply.biz.client.resource.converter.ResourceConverter;
import com.duobaoyu.dby.supply.biz.util.RemoteResultCheckUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName ResourceDictionaryAdminClientImpl
 * @createTime 14:23:00 2023/10/08
 */
@Component
@RequiredArgsConstructor
public class ResourceDictionaryAdminClientImpl implements ResourceDictionaryAdminClient {

    private final ResourceConverter resourceConverter;
    private final RemoteResourceDictionaryAdminService remoteResourceDictionaryAdminService;


    @Override
    public Boolean updateDictionary(DictionaryDTO dictionary) {
        R<Boolean> result = remoteResourceDictionaryAdminService.modify(resourceConverter.toResourceDictionary(dictionary), SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, dictionary);
        return result.getData();
    }

    @Override
    public Boolean removeDictionaryByIds(List<Long> dictionaryIds) {
        R<Boolean> result = remoteResourceDictionaryAdminService.remove(dictionaryIds, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, dictionaryIds);
        return result.getData();
    }

    @Override
    public Page<DictionaryVO> queryPage(DictionaryDTO dictionary) {
        R<Page<DictionaryTO>> result = remoteResourceDictionaryAdminService.queryPage(resourceConverter.toResourceDictionary(dictionary), SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, dictionary);
        return resourceConverter.toDictionaryPage(result.getData());
    }

    @Override
    public Long saveDictionary(DictionaryDTO dictionary) {
        R<Long> result = remoteResourceDictionaryAdminService.save(resourceConverter.toResourceDictionary(dictionary), SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, dictionary);
        return result.getData();
    }
}
